﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{
    public class CLSMAECOL
    {
        string codcol_col, nomcol_col;
        public string CODCOL_COL
        {
            get { return codcol_col; }
            set { codcol_col = value; }
        }

        public string NOMCOL_COL
        {
            get { return nomcol_col; }
            set { nomcol_col = value; }
        }

        MDOgeneral mod = new MDOgeneral();

        public Boolean ExisteColor()
        {
            try
            {
                string query = "select codcol_col from maecol where codcol_col='" + CODCOL_COL + "'";
                if (mod.consulta(query).Rows.Count > 0)
                {
                    return true;
                }
                return false;
            } catch (Exception e) { throw e; }
        }

        public DataTable Consultar()
        {
            try
            {
                string query = "select codcol_col as Codigo, nomcol_col as Nombre from maecol where codcol_col='" + CODCOL_COL + "'";
                DataTable dt = mod.consulta(query);
                if (dt.Rows.Count > 0)
                {
                    NOMCOL_COL = dt.Rows[0][1].ToString();
                }
                else
                {
                    NOMCOL_COL = "";
                }
                return dt;
            }catch (Exception e) { throw e; }
        }

        public void LimpiarValores()
        {
            CODCOL_COL = "";
            NOMCOL_COL = "";
        }

        public List<CLSMAECOL> ListarColores() 
        {
            try 
            {
                string query = "select codcol_col, nomcol_col from maecol";
                List<CLSMAECOL> lis = new List<CLSMAECOL>();
                DataTable val = mod.consulta(query);
                foreach (DataRow r in val.Rows) 
                {
                    lis.Add(new CLSMAECOL 
                    { 
                        CODCOL_COL=r["CODCOL_COL"].ToString(),
                        NOMCOL_COL=r["NOMCOL_COL"].ToString()                    
                    });
                }
                return lis;
            }
            catch (Exception ex) { throw ex; }
        }

        public List<CLSMAECOL> ListarColoresReferencia(string strRefrencia)
        {
            try
            {
                string query = "select c.codcol_col, c.nomcol_col from usu_dba.maeref a inner join usu_dba.colref b on a.codref_ref = b.codref_cxr inner join usu_dba.maecol c on b.codcol_cxr = c.codcol_col where a.codref_ref = '" + strRefrencia + "'";
                List<CLSMAECOL> lis = new List<CLSMAECOL>();
                DataTable val = mod.consulta(query);
                foreach (DataRow r in val.Rows)
                {
                    lis.Add(new CLSMAECOL
                    {
                        CODCOL_COL = r["CODCOL_COL"].ToString(),
                        NOMCOL_COL = r["NOMCOL_COL"].ToString()
                    });
                }
                return lis;
            }
            catch (Exception ex) { throw ex; }
        }

    }
}
